﻿package org.xhs.report.doc.ui
{
    import baidu.ui.managers.*;
    import baidu.wenku.common.*;
    import baidu.wenku.common.model.*;
    import baidu.wenku.doc.*;
    import baidu.wenku.doc.model.*;
    import flash.display.*;
    import flash.events.*;

    public class PPTViewer extends DocViewerBase implements IDocViewer
    {

        public function PPTViewer()
        {
            return;
        }// end function

        override protected function setPagesPos(event:LocatEvent = null) : void
        {
            var _loc_2:int = 0;
            var _loc_3:BlankPage = null;
            _loc_2 = 0;
            var _loc_4:uint = 0;
            var _loc_5:* = _pagesArray.length;
            docLocatModel.pagesYCoordinate = new Vector.<Number>;
            _loc_2 = 0;
            while (_loc_2 < _loc_5)
            {
                
                _loc_3 = _pagesArray[_loc_2] as BlankPage;
                _loc_3.scaleX = 1;
                _loc_3.visible = false;
                _loc_3.x = 0;
                _loc_3.y = 0;
                docLocatModel.pagesYCoordinate[_loc_2] = _loc_3.y;
                _loc_2++;
            }
            _pagesArray[docLocatModel.pageth].visible = true;
            container.addChild(_pagesArray[docLocatModel.pageth]);
            this.setOptimalZoom();
            return;
        }// end function

        override protected function showPage(event:Event = null) : void
        {
            _pageth = docLocatModel.pageth;
            var _loc_2:* = _pagesArray[_pageth] as Sprite;
            _loc_2.visible = true;
            container.addChild(_loc_2);
            return;
        }// end function

        override protected function docGlobalMouseMove(event:MouseEvent = null) : void
        {
            if (_inDocView && !_mouseDown)
            {
                if (screenModel.stage.mouseX <= screenModel.stageWidth / 3 && docLocatModel.pageth > 0)
                {
                    CursorManager.getInstance().showCursor(LeftCursor);
                }
                else if (screenModel.stage.mouseX >= 2 * screenModel.stageWidth / 3 && docLocatModel.pageth < (docLocatModel.pagesAllAvailable - 1))
                {
                    CursorManager.getInstance().showCursor(RightCursor);
                }
                else
                {
                    CursorManager.getInstance().showCursor(ReadCursor);
                }
            }
            return;
        }// end function

        override protected function docMouseClick(event:MouseEvent = null) : void
        {
            super.docMouseClick(event);
            if (screenModel.stage.mouseX <= screenModel.stageWidth / 3 && docLocatModel.pageth > 0)
            {
                var _loc_2:* = docLocatModel;
                var _loc_3:* = docLocatModel.pageth - 1;
                _loc_2.pageth = _loc_3;
            }
            else if (screenModel.stage.mouseX >= 2 * screenModel.stageWidth / 3 && docLocatModel.pageth < (docLocatModel.pagesAllAvailable - 1))
            {
                var _loc_2:* = docLocatModel;
                var _loc_3:* = docLocatModel.pageth + 1;
                _loc_2.pageth = _loc_3;
            }
            this.docGlobalMouseMove();
            return;
        }// end function

        override public function setOptimalZoom() : void
        {
            var _loc_1:Number = NaN;
            var _loc_2:Number = NaN;
            var _loc_3:Number = NaN;
            _loc_1 = (screenModel.stageWidth - DocConfig.DV_WIDTH_LEFT_PADDING - Config.DV_WIDTH_RIGHT_SCROLLBAR - DocConfig.DV_WIDTH_RIGHT_PADDING) / Config.pageWidth;
            _loc_2 = (screenModel.stageHeight - Config.TB_HEIGHT - Config.SB_HEIGHT - Config.DV_WIDTH_RIGHT_SCROLLBAR - 8) / Config.pageHeight;
            zoomModel.zoomValues[0] = Math.min(_loc_2, _loc_1);
            zoomModel.zoomValues[1] = Math.max(_loc_2, _loc_1);
            var _loc_4:int = 2;
            while (_loc_4 < zoomModel.zoomLevelNum)
            {
                
                zoomModel.zoomValues[_loc_4] = zoomModel.zoomValues[1] * Number(DocZoomModel.ZOOM_LEVELS[_loc_4]);
                _loc_4++;
            }
            _loc_3 = Math.min(_loc_1, _loc_2);
            zoomModel.zoomLevel = 0;
            resetContainerPosition();
            return;
        }// end function

        override public function set zoomNumber(param1:Number) : void
        {
            if (!scrollPane || !container)
            {
                return;
            }
            _zoomNumber = param1;
            container.scaleX = _zoomNumber;
            container.scaleY = _zoomNumber;
            scrollPane.update();
            container.x = Math.max((screenModel.stageWidth - container.width - (scrollPane.maxVScrollPosition > 0 ? (Config.DV_WIDTH_RIGHT_SCROLLBAR) : (0))) / 2, 0);
            container.y = Math.max((docLocatModel.viewportHeight - container.height - (scrollPane.maxHScrollPosition > 0 ? (Config.DV_WIDTH_RIGHT_SCROLLBAR) : (0))) / 2, 0);
            scrollPane.update();
            scrollPane.hScrollPosition = scrollPane.maxHScrollPosition / 2;
            dispatchEvent(new LocatEvent(LocatEvent.ZOOM_CHANGED));
            return;
        }// end function

    }
}
